//=================================================================================================================================
//
// Author: Maurice Ribble
//         3D Application Research Group
//         ATI Research, Inc.
//
// More definitions for the Scene class.
//
//=================================================================================================================================
// $Id: //depot/3darg/Tools/Handheld/esTestApps/esTriangle/src/Draw.cpp#1 $ 
// 
// Last check-in:  $DateTime: 2008/01/23 11:45:40 $ 
// Last edited by: $Author: dginsbur $
//=================================================================================================================================
//   (C) ATI Research, Inc. 2006 All rights reserved. 
//=================================================================================================================================

#include "Scene.h"

static const float g_vertexPositions[] = {
   -0.7f, -0.7f,  1.0f,  1.0f,
    0.7f, -0.7f,  1.0f,  1.0f,
   -0.7f,  0.7f,   1.0f, 1.0f,
    0.7f,  0.7f,   1.0f, 1.0f,
};

static const float g_vertexColors[] = {
   1.0f, 1.0f, 0.0f, 1.0f,
   1.0f, 1.0f, 1.0f, 1.0f,
   1.0f, 0.0f, 0.0f, 1.0f,
   1.0f, 0.0f, 1.0f, 1.0f,
};

static const float g_vertexTexcoord[] = {
   0.f, 0.f,    
   1.f, 0.f,    
   0.0f, 1.f,    
   1.0f, 1.f,    
};

static const uint32 g_indices[] = {
   0, 1, 2, 3,
};

//=================================================================================================================================
///
/// Draws the current frame.
///
/// \param none
///
/// \return null
//=================================================================================================================================
void Scene::drawFrame()
{
   glClearColor( m_clearColor[0], m_clearColor[1], m_clearColor[2], m_clearColor[3] );
   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT| GL_STENCIL_BUFFER_BIT );

   GLuint progHandle = m_uniforms.getProgramHandle( "mainProg" );
   glUseProgram( progHandle );

   glVertexAttribPointer( 0, 4, GL_FLOAT, 0, 0, g_vertexPositions );
   glEnableVertexAttribArray( 0 );
   glVertexAttribPointer( 1, 4, GL_FLOAT, 0, 0, g_vertexColors );
   glEnableVertexAttribArray( 1 );
   glVertexAttribPointer( 2, 2, GL_FLOAT, 0, 0, g_vertexTexcoord );
   glEnableVertexAttribArray( 2 );

   // draw with client side arrays (in real apps you should use cached VBOs which is much better for performance)
   glDrawElements( GL_TRIANGLE_STRIP, 3, GL_UNSIGNED_INT, g_indices );
}

